package ch.bfh.java.directorysynchronizer.presentation.actionlisteners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;

import ch.bfh.java.directorysynchronizer.presentation.items.Workbench;

public class LogfileDirectoryButtonListener implements ActionListener
{
	
	private Workbench workbench;
	private JFileChooser chooser;
	
	public LogfileDirectoryButtonListener(Workbench wb){
		this.workbench = wb;
		this.chooser = new JFileChooser();
	}

	@Override
    public void actionPerformed(ActionEvent e)
    {
		
		chooser.setApproveButtonText("Save logfile");
		chooser.setDialogTitle("Save logfile");
		chooser.setCurrentDirectory(new File("C:\\"));

		if(chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION){
			
			workbench.setLogfileDirectoryFile(chooser.getSelectedFile());
			workbench.getLogfileDirectoryTextfield().setText(
			        workbench.getLogfileDirectoryFile().getAbsolutePath());
		}
    }

}
